2 class Bug32003_Test extends Sugar_PHPUnit_Framework_TestCase {
5 var $original_current_user_id;
11 $dictionary['iFrame'] = array('table' => 'iframes'
23 'vname' => 'LBL_LIST_NAME',
27 'importable' => 'required',
32 'vname' => 'LBL_LIST_URL',
36 'importable' => 'required',
41 'vname' => 'LBL_LIST_TYPE',
48 'name' => 'placement',
49 'vname' => 'LBL_LIST_PLACEMENT',
53 'importable' => 'required',
58 'vname' => 'LBL_LIST_STATUS',
65 'vname' => 'LBL_DELETED',
71 'name' => 'date_entered',
72 'vname' => 'LBL_DATE_ENTERED',
78 'name' => 'date_modified',
79 'vname' => 'LBL_DATE_MODIFIED',
85 'name' => 'created_by',
86 'rname' => 'user_name',
87 'id_name' => 'modified_user_id',
88 'vname' => 'LBL_ASSIGNED_TO',
89 'type' => 'assigned_user_name',
97 array('name' =>'iframespk', 'type' =>'primary', 'fields'=>array('id')),
98 array('name' =>'idx_cont_name', 'type'=>'index', 'fields'=>array('name','deleted'))
103 $dictionary['Feed'] = array('table' => 'feeds', 'comment' => 'RSS Feeds'
112 'comment' => 'Unique identifier'
117 'vname' => 'LBL_CREATED_BY',
121 'comment' => 'Record deletion indicator'
125 'name' => 'date_entered',
126 'vname' => 'LBL_DATE_ENTERED',
127 'type' => 'datetime',
129 'comment' => 'Date record created'
133 'name' => 'date_modified',
134 'vname' => 'LBL_DATE_MODIFIED',
135 'type' => 'datetime',
137 'comment' => 'Date record last modified'
139 'modified_user_id' =>
141 'name' => 'modified_user_id',
142 'rname' => 'user_name',
143 'id_name' => 'modified_user_id',
144 'vname' => 'LBL_ASSIGNED_TO',
145 'type' => 'assigned_user_name',
151 'comment' => 'User who last modified record'
153 'assigned_user_id' =>
155 'name' => 'assigned_user_id',
156 'rname' => 'user_name',
157 'id_name' => 'assigned_user_id',
158 'vname' => 'LBL_ASSIGNED_TO',
159 'type' => 'assigned_user_name',
164 'comment' => 'User assigned to record'
168 'name' => 'created_by',
169 'rname' => 'user_name',
170 'id_name' => 'modified_user_id',
171 'vname' => 'LBL_ASSIGNED_TO',
172 'type' => 'assigned_user_name',
176 'comment' => 'User that created record'
183 'vname' => 'LBL_TITLE',
184 'comment' => 'Title of RSS feed'
188 'name' => 'description',
190 'vname' => 'LBL_DESCRIPTION',
191 'comment' => 'Description of RSS feed'
198 'vname' => 'LBL_URL',
199 'comment' => 'URL that represents the RSS feed',
200 'importable' => 'required',
204 'name' => 'created_by_link',
206 'relationship' => 'feeds_created_by',
207 'vname' => 'LBL_CREATED_BY_USER',
208 'link_type' => 'one',
213 'modified_user_link' =>
215 'name' => 'modified_user_link',
217 'relationship' => 'feeds_modified_user',
218 'vname' => 'LBL_MODIFIED_BY_USER',
219 'link_type' => 'one',
224 'assigned_user_link' =>
226 'name' => 'assigned_user_link',
228 'relationship' => 'feeds_assigned_user',
229 'vname' => 'LBL_ASSIGNED_TO_USER',
230 'link_type' => 'one',
237 'relationships' => array (
239 'feeds_assigned_user' =>
240 array('lhs_module'=> 'Users', 'lhs_table'=> 'users', 'lhs_key' => 'id',
241 'rhs_module'=> 'Feeds', 'rhs_table'=> 'feeds', 'rhs_key' => 'assigned_user_id',
242 'relationship_type'=>'one-to-many')
244 ,'feeds_modified_user' =>
245 array('lhs_module'=> 'Users', 'lhs_table'=> 'users', 'lhs_key' => 'id',
246 'rhs_module'=> 'Feeds', 'rhs_table'=> 'feeds', 'rhs_key' => 'modified_user_id',
247 'relationship_type'=>'one-to-many')
249 ,'feeds_created_by' =>
250 array('lhs_module'=> 'Users', 'lhs_table'=> 'users', 'lhs_key' => 'id',
251 'rhs_module'=> 'Feeds', 'rhs_table'=> 'feeds', 'rhs_key' => 'created_by',
252 'relationship_type'=>'one-to-many')
255 , 'indices' => array (
256 array('name' =>'feedspk', 'type' =>'primary', 'fields'=>array('id')),
257 array('name' =>'idx_feed_name', 'type'=>'index', 'fields'=>array('title','deleted'))
262 VardefManager::createVardef('Feeds','Feed', array(
265 require_once('include/database/DBManagerFactory.php');
266 $db = DBManagerFactory::getInstance();
268 if(!$db->tableExists('iframes')){
269 $db->createTableParams('iframes', $dictionary['iFrame']['fields'], $dictionary['iFrame']['indices']);
272 if(!$db->tableExists('feeds')){
273 $db->createTableParams('feeds', $dictionary['Feed']['fields'], $dictionary['Feed']['indices']);
277 $moduleList['Feeds'] = 'Feeds';
278 $moduleList['iFrames'] = 'iFrames';
280 require_once("modules/MySettings/TabController.php");
281 $this->controller = new TabController();
283 global $current_user;
284 if ( !( $current_user instanceOf User ) ) {
285 $current_user = new User;
286 $current_user->retrieve('1');
288 $this->original_current_user_id = $current_user->id;
291 function tearDown() {
292 $db = DBManagerFactory::getInstance();
293 if($db->tableExists('iframes')) {
294 $db->dropTableName('iframes');
297 if($db->tableExists('feeds')) {
298 $db->dropTableName('feeds');
302 require_once("modules/MySettings/TabController.php");
303 $this->controller = new TabController();
306 $keys = array_flip($moduleList);
307 if(in_array('Feeds', $moduleList)) {
308 unset($moduleList[$keys['Feeds']]);
311 if(in_array('iFrames', $moduleList)) {
312 unset($moduleList[$keys['iFrames']]);
315 $this->controller->set_system_tabs($moduleList);
317 if(file_exists('custom/Extension/application/Ext/Include/Feed.php')) {
318 unlink('custom/Extension/application/Ext/Include/Feed.php');
321 if(file_exists('custom/Extension/application/Ext/Include/iFrame.php')) {
322 unlink('custom/Extension/application/Ext/Include/iFrame.php');
325 global $current_user;
326 $current_user->retrieve($this->original_current_user_id);
330 function disabled_post_install_upgrade_with_iframes() {
331 $db = DBManagerFactory::getInstance();
332 $db->query('INSERT into iframes(id, name, url) values (\'' . mktime() . '\', \'test\', \'www.test.com\')');
333 hide_iframes_and_feeds_modules();
334 $this->assertTrue($db->tableExists('iframes'));
335 $this->assertTrue(file_exists('custom/Extension/application/Ext/Include/iFrame.php'));
339 function disabled_post_install_upgrade_without_iframes() {
340 hide_iframes_and_feeds_modules();
341 $db = DBManagerFactory::getInstance();
342 $this->assertTrue(!$db->tableExists('iframes'));
344 $this->assertTrue(!file_exists('custom/Extension/application/Ext/Include/iFrame.php'));
348 function disabled_post_install_upgrade_with_feeds() {
349 $this->markTestSkipped("Skip test_post_install_upgrade_with_feeds");
350 $tabs = $this->controller->get_tabs_system();
351 echo var_export($tabs, true);
353 //If it is hidden, set it to show
354 if(isset($tabs[1]['Feeds'])) {
355 $db = DBManagerFactory::getInstance();
356 $db->query('DELETE FROM config WHERE category = \'MySettings\' AND name = \'tab\'');
357 unset($tabs[1]['Feeds']);
358 $tabs[0]['Feeds'] = 'Feeds';
360 $administration = new Administration();
361 $serialized = base64_encode(serialize($moduleList));
362 $administration->saveSetting('MySettings', 'tab', $serialized);
363 $this->controller->set_system_tabs($tabs);
367 //It's as if this never changes
368 $tabs = $this->controller->get_tabs_system();
369 echo var_export($tabs, true);
372 hide_iframes_and_feeds_modules();
373 $this->assertTrue($db->tableExists('feeds'));
374 $this->assertTrue(file_exists('custom/Extension/application/Ext/Include/Feed.php'));
378 function disabled_post_install_upgrade_without_feeds() {
379 hide_iframes_and_feeds_modules();
380 $db = DBManagerFactory::getInstance();
381 $this->assertTrue(!$db->tableExists('feeds'));
382 $this->assertTrue(!file_exists('custom/Extension/application/Ext/Include/Feed.php'));
386 * Added a minimum of 1 test to make sure that
388 function test_donothing() {
392 function disabled_dashlets_module_changed() {
394 $db = DBManagerFactory::getInstance();
395 $query = "SELECT id, contents, assigned_user_id FROM user_preferences WHERE deleted = 0 AND category = 'Home'";
396 $result = $db->query($query, true, "Unable to update iFrames and Feeds dashlets!");
397 while ($row = $GLOBALS['db']->fetchByAssoc($result)) {
398 $content = unserialize(base64_decode($row['contents']));
399 $assigned_user_id = $row['assigned_user_id'];
400 $record_id = $row['id'];
401 $current_user = new User();
402 $current_user->retrieve($row['assigned_user_id']);
404 if(!empty($content['dashlets']) && !empty($content['pages'])){
405 $originalDashlets = $content['dashlets'];
406 $originalPages = $content['pages'];
408 //Determine if the original perference has already had the two dashlets or not
409 foreach($originalDashlets as $key=>$ds){
411 if(!empty($ds['options']['title']) && $ds['options']['title'] == 'LBL_DASHLET_DISCOVER_SUGAR_PRO'){
412 $originalDashlets[$key]['module'] = 'iFrames';
414 if(!empty($ds['options']['title']) && $ds['options']['title'] == 'LBL_DASHLET_SUGAR_NEWS'){
415 $originalDashlets[$key]['module'] = 'iFrames';
419 $current_user->setPreference('dashlets', $originalDashlets, 0, 'Home');
420 $current_user->setPreference('pages', $originalPages, 0, 'Home');
425 hide_iframes_and_feeds_modules();
426 $result = $db->query($query, true, "Unable to update iFrames and Feeds dashlets!");
427 $not_home_module = false;
429 while ($row = $db->fetchByAssoc($result)) {
430 $content = unserialize(base64_decode($row['contents']));
431 $assigned_user_id = $row['assigned_user_id'];
432 $record_id = $row['id'];
433 $current_user = new User();
434 $current_user->retrieve($row['assigned_user_id']);
436 if(!empty($content['dashlets']) && !empty($content['pages'])){
437 $originalDashlets = $content['dashlets'];
438 $originalPages = $content['pages'];
440 //Determine if the original perference has already had the two dashlets or not
441 foreach($originalDashlets as $key=>$ds){
442 if(!empty($ds['options']['title']) && $ds['options']['title'] == 'LBL_DASHLET_DISCOVER_SUGAR_PRO' && $originalDashlets[$key]['module'] != 'Home') {
443 $not_home_module = true;
445 if(!empty($ds['options']['title']) && $ds['options']['title'] == 'LBL_DASHLET_SUGAR_NEWS' && $originalDashlets[$key]['module'] != 'Home'){
446 $not_home_module = true;
452 $this->assertFalse($not_home_module, 'Assert that dashlet\'s module were correctly set to Home module');
458 //BEGIN INLINE METHODS FROM BUILD (post_install.php)
461 * hide_iframes_and_feeds_modules
462 * This method determines whether or not to hide the iFrames and Feeds module
463 * for an upgrade to 551
465 function hide_iframes_and_feeds_modules() {
468 _logThis('Updating the iFrames Dashlets', $path);
469 $query = "SELECT id, contents, assigned_user_id FROM user_preferences WHERE deleted = 0 AND category = 'Home'";
470 $result = $GLOBALS['db']->query($query, true, "Unable to update iFrames and Feeds dashlets!");
471 while ($row = $GLOBALS['db']->fetchByAssoc($result)) {
472 $content = unserialize(base64_decode($row['contents']));
473 $assigned_user_id = $row['assigned_user_id'];
474 $record_id = $row['id'];
475 $current_user = new User();
476 $current_user->retrieve($row['assigned_user_id']);
478 if(!empty($content['dashlets']) && !empty($content['pages'])){
479 $originalDashlets = $content['dashlets'];
480 $originalPages = $content['pages'];
482 //Determine if the original perference has already had the two dashlets or not
483 foreach($originalDashlets as $key=>$ds){
484 if(!empty($ds['options']['title']) && $ds['options']['title'] == 'LBL_DASHLET_DISCOVER_SUGAR_PRO'){
485 $originalDashlets[$key]['module'] = 'Home';
487 if(!empty($ds['options']['title']) && $ds['options']['title'] == 'LBL_DASHLET_SUGAR_NEWS'){
488 $originalDashlets[$key]['module'] = 'Home';
492 $current_user->setPreference('dashlets', $originalDashlets, 0, 'Home');
493 $current_user->setPreference('pages', $originalPages, 0, 'Home');
497 $remove_iframes = false;
498 $remove_feeds = false;
500 //Check if we should remove iframes. Use the count of entries in iframes table
501 $result = $GLOBALS['db']->query('SELECT count(id) as total from iframes');
502 if(!empty($result)) {
503 $row = $GLOBALS['db']->fetchByAssoc($result);
504 if($row['total'] == 0) {
505 $remove_iframes = true;
509 //Check if we should remove Feeds. We check if the tab is hidden
510 require_once("modules/MySettings/TabController.php");
511 $controller = new TabController();
512 $tabs = $controller->get_tabs_system();
514 //If the Feeds tab is hidden then remove it
515 if(!isset($tabs[0]['Feeds'])) {
516 $remove_feeds = true;
520 //Remove the modules/Feeds files
521 if(is_dir('modules/Feeds')) {
522 _logThis('Removing the Feeds files', $path);
523 rmdir_recursive('modules/Feeds');
527 _logThis('Removing the Feeds table', $path);
528 $GLOBALS['db']->dropTableName('feeds');
530 if(file_exists('modules/Feeds')) {
531 _logThis('Writing Feed.php module to custom/Extension/application/Ext/Include', $path);
532 write_to_modules_ext_php('Feed', 'Feeds', 'modules/Feeds/Feed.php', true);
536 if($remove_iframes) {
537 //Remove the module/iFrames files
538 if(is_dir('modules/iFrames')) {
539 _logThis('Removing the iFrames files', $path);
540 rmdir_recursive('modules/iFrames');
544 _logThis('Removing the iframes table', $path);
545 $GLOBALS['db']->dropTableName('iframes');
547 if(file_exists('modules/iFrames')) {
548 _logThis('Writing iFrame.php module to custom/Extension/application/Ext/Include', $path);
549 write_to_modules_ext_php('iFrame', 'iFrames', 'modules/iFrames/iFrame.php', true);
554 function write_to_modules_ext_php($module, $class, $path, $show=false) {
556 global $beanList, $beanFiles;
557 include('include/modules.php');
558 if(!isset($beanFiles[$module])) {
559 $str = "<?php \n //WARNING: The contents of this file are auto-generated\n";
561 if(!empty($module) && !empty($class) && !empty($path)){
562 $str .= "\$beanList['$module'] = '$class';\n";
563 $str .= "\$beanFiles['$class'] = '$path';\n";
565 $str .= "\$moduleList[] = '$module';\n";
567 $str .= "\$modules_exempt_from_availability_check['$module'] = '$module';\n";
568 $str .= "\$modInvisList[] = '$module';\n";
573 if(!file_exists("custom/Extension/application/Ext/Include")) {
574 mkdir_recursive("custom/Extension/application/Ext/Include", true);
577 $out = sugar_fopen("custom/Extension/application/Ext/Include/{$module}.php", 'w');
584 function _logThis($string, $path) {
585 //echo $string . "\n";